package com.ludomancy.gamelib;

public class Layout
{	
	public static void doLayout(Widget[][] widgets, int gapWidth, int gapHeight, int offsetX, int offsetY)
	{
		Widget lastVertical = null;
		for (int y = 0 ; y != widgets.length ; y++)
		{
			Widget lastHorizontal = null;
			for (int x = 0 ; x != widgets[y].length ; x++)
			{
				Widget cur = widgets[y][x];
				int relx = offsetX;
				int rely = offsetY;
				if(lastHorizontal != null)
				{
					relx = lastHorizontal.getX() + lastHorizontal.getWidth() + gapWidth;
				}
				if(lastVertical != null)
				{
					rely = lastVertical.getY() + lastVertical.getHeight() + gapHeight;
				}
				cur.setRelativePosition(cur.getX() + relx, cur.getY() + rely);
				lastHorizontal = cur;
			}
			lastVertical = widgets[y][0];
		}		
	}
	
	public static void doLayout(Widget[][] widgets, int gap, int offsetX, int offsetY)
	{
		doLayout(widgets, gap, gap, offsetX, offsetY);
	}
}
